import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

const Index = () => import('../page/index')
const Music = () => import('../page/music')
const Poster = () => import('../page/poster')
const Compose = () => import('../page/compose')
const Daybill = () => import('../page/daybill')
const Clear = () => import('../page/clear')

const router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/index'
    },
    {
      path: '/index',
      name: 'Index',
      component: Index,
      meta: {
        title: '搭档跑'
      }
    },
    {
      path: '/clear',
      name: 'Clear',
      component: Clear,
      meta: {
        title: '清除缓存页'
      }
    },
    {
      path: '/music',
      name: 'Music',
      component: Music,
      mate: {
        title: '选择曲子'
      }
    },
    {
      path: '/poster',
      name: 'Poster',
      component: Poster,
      mate: {
        title: '上传照片'
      }
    },
    {
      path: '/compose',
      name: 'Compose',
      component: Compose,
      mate: {
        title: '合成照片'
      }
    },
    {
      path: '/daybill',
      name: 'Daybill',
      component: Daybill,
      mate: {
        title: '海报展示页'
      }
    }
  ]
})
router.beforeEach((to, from, next) => {
  if (to.meta.title) { // 如果设置标题，拦截后设置标题
    document.title = to.meta.title
  }
  next()
})
export default router
